#ifndef HEAD_H
#define HEAD_H
#include<iostream>
using namespace std;

struct node{
    node* nx;
    int data;
};

class arraylist{
private:
    node*head;
    node*tail;
    node*current;
    int length=0;
public:
    arraylist();
    void length_input();
    void creatlist(int i);
    void showlist();
    ~arraylist();
};


arraylist::arraylist(){
    head=tail=current=NULL;
    length_input();
}

void arraylist::length_input(){
    cout<<"please input the length of arraylist:";
    cin>>length;
        if(length){
            creatlist(length);
        }
        else{
            length_input();
        }
}


void arraylist::creatlist(int i){
    int counter=0;

    head=tail=new node;
    current=head;

    while(counter<i){
        tail=current=current->nx=new node;

        cout<<"\ninput the no."<<++counter<<" number: ";
        cin>>current->data;
    }

    tail->nx=NULL;
//    delete current;别在这贱兮兮的干这活！去掉了这个你试试！
}


arraylist::~arraylist(){
    while(head!=NULL){
        current=head;
        head=head->nx;
        delete current;
    }
    head=tail=NULL;
}


void arraylist::showlist(){
    current=head->nx;
    cout<<endl;

    while(current!=NULL){
        cout<<current->data<<"\t";
        current=current->nx;\
    }

    cout<<endl;
}


#endif // HEAD_H
